package com.woniuxy.utils;


import com.woniuxy.exception.DdException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class QjException {

    /**
     * 全局异常
     */
    //匹配自定义异常
    @ExceptionHandler(DdException.class)
    public Result handlerwoniuxyException(DdException e){
        return Result.fail(e.getCode(),e.getMessage(),null);
    }
    //总异常兜底
    @ExceptionHandler(Exception.class)
    public Result exception(Exception e){
        System.out.println(e);
        return Result.fail(500,"服务器繁忙",null);
    }
    //权限异常处理
    @ExceptionHandler(AccessDeniedException.class)
    public Result accessDeniedException(AccessDeniedException e){
        return Result.fail(503,e.getMessage(),null);
    }
}
